package com.vip.jwt.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vip.jwt.common.entity.R;
import com.vip.jwt.entity.Permission;
import com.vip.jwt.mapper.PermissionMapper;
import com.vip.jwt.service.PermissionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author vip
 * @since 2021-05-04
 */
@RestController
@RequestMapping("/api/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    @PostMapping
    public Object addPermission(@RequestBody Permission permission){
        permissionService.save(permission);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public Object deleteById(@PathVariable String id){
        permissionService.removeById(id);
        return R.ok();
    }

    @PutMapping
    public Object updatePermission(@RequestBody Permission permission){
        permissionService.updateById(permission);
        return R.ok();
    }

    @GetMapping
    public Object permissions(){
        List<Permission> permissions = permissionService.list();
        return R.ok().data("data",permissions);
    }

    @GetMapping("/{page}/{limit}")
    public Object pagePermissions(@PathVariable Long page,@PathVariable Long limit){
        Page<Permission> permissionPage = new Page<>(page,limit);
        permissionPage = permissionService.page(permissionPage);
        return R.ok().data("data",permissionPage);
    }

}

